package com.primb.bench.common.viewmodel;

import android.content.Context;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.primb.bench.R;
import com.zhy.autolayout.AutoLinearLayout;

/**
 * Created by Chen on 2017/5/10.
 * 功能描述：申请信息数据驱动模型
 */

public class ViewApplyInfoEntity implements Parcelable {
    private String name;
    private String date;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void addView(Context context, ViewGroup viewGroup) {
        AutoLinearLayout layout = new AutoLinearLayout(context);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setBackgroundColor(ContextCompat.getColor(context, R.color.white));
        TextView tvKey = new TextView(context);
        tvKey.setGravity(Gravity.CENTER);
        tvKey.setTextSize(18);
        tvKey.setTextColor(ContextCompat.getColor(context, R.color.gray_333333));
        if (name != null)
            tvKey.setText(name);
        AutoLinearLayout.LayoutParams paramsLeft = new AutoLinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        tvKey.setPadding(80, 40, 0, 20);
        tvKey.setLayoutParams(paramsLeft);
        layout.addView(tvKey);

        TextView tvValue = new TextView(context);
        tvValue.setGravity(Gravity.CENTER);
        tvValue.setTextSize(14);
        if (date != null) {
            tvValue.setText("申请时间：" + date);
        }
        AutoLinearLayout.LayoutParams paramsRight = new AutoLinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
        tvValue.setLayoutParams(paramsRight);
        tvValue.setPadding(80, 20, 50, 20);
        layout.addView(tvValue);
        viewGroup.addView(layout);
        View line = new View(context);
        line.setBackgroundColor(ContextCompat.getColor(context, R.color.gray_efefef));
        viewGroup.addView(line, new AutoLinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 10));
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeString(this.date);
    }

    public ViewApplyInfoEntity() {
    }

    public ViewApplyInfoEntity(String key, String value) {
        this.name = key;
        this.date = value;
    }

    protected ViewApplyInfoEntity(Parcel in) {
        this.name = in.readString();
        this.date = in.readString();
    }

    public static final Creator<ViewApplyInfoEntity> CREATOR = new Creator<ViewApplyInfoEntity>() {
        @Override
        public ViewApplyInfoEntity createFromParcel(Parcel source) {
            return new ViewApplyInfoEntity(source);
        }

        @Override
        public ViewApplyInfoEntity[] newArray(int size) {
            return new ViewApplyInfoEntity[size];
        }
    };
}
